package com.yaorange.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yaorange.teaching.bo.ExamRecordBo;
import com.yaorange.teaching.bo.ScoreDistributionBo;
import com.yaorange.teaching.bo.ScoreTrendBo;
import com.yaorange.teaching.domain.YaExamDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaExamRecord;
import com.yaorange.teaching.service.IYaExamRecordService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 学生成绩记录Controller
 *
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/examrecord")
public class YaExamRecordController extends BaseController
{
    @Autowired
    private IYaExamRecordService yaExamRecordService;

    @RequiresPermissions("teaching:exam_record:list")
    @GetMapping("/score/distribution")
    public AjaxResult queryScoreDistribution()
    {
        ScoreDistributionBo result = yaExamRecordService.queryScoreDistribution();
        return AjaxResult.success(result);
    }

    @RequiresPermissions("teaching:exam_record:list")
    @GetMapping("/score/trend")
    public AjaxResult queryScoreTrend()
    {
        ScoreTrendBo result = yaExamRecordService.queryScoreTrend();
        return AjaxResult.success(result);
    }

    @RequiresPermissions("teaching:exam_record:list")
    @GetMapping("/week/last")
    public AjaxResult queryLastWeek(@RequestParam("classesId")Long classesId,@RequestParam("stage")Long stage)
    {
        Integer lastWeek = yaExamRecordService.queryLastWeek(classesId,stage);
        return AjaxResult.success(lastWeek);
    }
    /**
     * 查询学生成绩记录列表
     */
    @RequiresPermissions("teaching:examrecord:list")
    @GetMapping("/detail/list/{classesId}")
    public TableDataInfo list(@PathVariable("classesId")Long classesId)
    {
        List<YaExamDetail> list = yaExamRecordService.selectYaExamDetailList(classesId);
        return getDataTable(list);
    }

    /**
     * 查询学生成绩记录列表
     */
    @RequiresPermissions("teaching:examrecord:list")
    @GetMapping("/list")
    public TableDataInfo list(YaExamRecord yaExamRecord)
    {
        startPage();
        List<YaExamRecord> list = yaExamRecordService.selectYaExamRecordList(yaExamRecord);
        return getDataTable(list);
    }

    /**
     * 导出学生成绩记录列表
     */
    @RequiresPermissions("teaching:examrecord:export")
    @Log(title = "学生成绩记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaExamRecord yaExamRecord)
    {
        List<YaExamRecord> list = yaExamRecordService.selectYaExamRecordList(yaExamRecord);
        ExcelUtil<YaExamRecord> util = new ExcelUtil<YaExamRecord>(YaExamRecord.class);
        util.exportExcel(response, list, "学生成绩记录数据");
    }

    /**
     * 获取学生成绩记录详细信息
     */
    @RequiresPermissions("teaching:examrecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaExamRecordService.selectYaExamRecordById(id));
    }

    /**
     * 新增学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:add")
    @Log(title = "学生成绩记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamRecordBo yaExamRecord)
    {
        return toAjax(yaExamRecordService.insertYaExamRecord(yaExamRecord));
    }

    /**
     * 修改学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:edit")
    @Log(title = "学生成绩记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaExamRecord yaExamRecord)
    {
        return toAjax(yaExamRecordService.updateYaExamRecord(yaExamRecord));
    }

    /**
     * 删除学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:remove")
    @Log(title = "学生成绩记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaExamRecordService.deleteYaExamRecordByIds(ids));
    }
}
